/*
 * @Author: nengwu 409791297@qq.com
 * @Date: 2020-06-30 21:38:56
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-08-15 21:47:20
 * @description: 
 */ 
import fetch from './fetch'

export default function createAction(options) {
  const { url, params = {}, method = 'POST', fetchOptions, cb, type, form = false } = options
  return (dispatch) => {
    return fetch({ url, data: params, method, actionType: type, form, ...fetchOptions }).then((res) => {
      dispatch({ type,  params, data: cb ? cb(res) : res })
      return res
    })
  }
}
